// TypeScript file
//点击可跳动按钮 基类
class TbitMap extends egret.Bitmap {

    private _touchAnimation: boolean = false;


    public get touchAnimation(): boolean {
        return this._touchAnimation;
    }
    public set touchAnimation(value: boolean) {
        this._touchAnimation = value;
        if (value) {
            this.touchEnabled = true;
            if (!this.hasEventListener(egret.TouchEvent.TOUCH_BEGIN)) {
                this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchAnimationAction, this);
            }
        } else {
            if (this.hasEventListener(egret.TouchEvent.TOUCH_BEGIN)) {
                this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchAnimationAction, this);
            }
        }
    }

    private touchAnimationAction(event: egret.TouchEvent): void {
        egret.Tween.removeTweens(this);
        egret.Tween.get(this).to({ scaleX: 1.1, scaleY: 1.1 }, 50).to({ scaleX: 1, scaleY: 1 }, 50).call(function () {
            egret.Tween.removeTweens(this);
        });
    }


    constructor() {
        super();
        // this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.viewDidDisappear, this);
    }

    private viewDidDisappear(event: egret.Event): void {
        if (this.hasEventListener(egret.TouchEvent.TOUCH_BEGIN)) {
            this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchAnimationAction, this);
        }
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.viewDidDisappear, this);
    }

}